Object.defineProperty(exports, "__esModule", {
  value: true
});
var $z1SoundManager = require("SoundManager");
var $z1Pool = require("Pool");
var $z1BattleGround2Ctrl = require("BattleGround2Ctrl");
var $z1Gate2 = require("Gate2");
var $z1Role2 = require("Role2");
var cc__decorator = cc._decorator;
var ccp_ccclass = cc__decorator.ccclass;
var ccp_property = cc__decorator.property;
var def_Bullet2 = function (e) {
  function _ctor() {
    var t = null !== e && e.apply(this, arguments) || this;
    t.label = null;
    t.bodySpr = null;
    t.bodySFS = [];
    t.collBody = null;
    t.par = null;
    t.v = 500;
    t.dmg = 1;
    t.hitTimes = 0;
    t.fCount = 0;
    t.state = 0;
    t.cIdx = 0;
    t.tarColHandle = null;
    return t;
  }
  var o;
  __extends(_ctor, e);
  o = _ctor;
  _ctor.prototype.init = function (e, t, o) {
    this.node.x = e;
    this.node.y = t;
    this.par = o.par;
    this.hitTimes = 0;
    this.v = $z1BattleGround2Ctrl.default.JSONManager.ConfigBattle[6].v[6];
    this.dmg = o.dmg;
    this.bodySpr.getComponent(cc.Sprite).spriteFrame = this.bodySFS[0];
    this.cIdx = Math.floor((this.node.x + 299) / 10);
    this.par.bulletHandles[this.cIdx] || (this.par.bulletHandles[this.cIdx] = []);
    this.par.bulletHandles[this.cIdx].push(this.node);
    this.collBody.enabled = 1 === this.par.bulletHandles[this.cIdx].length;
    $z1SoundManager.default.playEffect2(0);
    this.state = 0;
  };
  _ctor.prototype.remove = function (e) {
    this.updateBulletHandles();
    if (1 === e) {
      this.v = 0;
      this.state = 1;
      this.fCount = 0;
      this.bodySpr.getComponent(cc.Sprite).spriteFrame = this.bodySFS[1];
    } else {
      this.node.parent.getComponent($z1Pool.default).destroyPoolItem(this.node);
    }
  };
  _ctor.prototype.start = function () {};
  _ctor.prototype.onCollisionEnter = function (e) {
    o.collTimes++;
    if (!(this.hitTimes > 0)) {
      if (1 === e.tag) {
        e.node.getComponent($z1Role2.default).beHit(this);
      } else {
        3 === e.tag && e.node.getComponent($z1Gate2.default).beHit(this);
      }
      this.collBody.enabled = false;
      this.hitTimes++;
      this.remove(1);
    }
  };
  _ctor.prototype.updateBulletHandles = function () {
    this.par.bulletHandles[this.cIdx].shift();
    this.par.bulletHandles[this.cIdx].length >= 1 && (this.par.bulletHandles[this.cIdx][0].getComponent(o).collBody.enabled = true);
  };
  _ctor.prototype.update = function (e) {
    if (10 === this.par.state) {
      if (1 === this.state) {
        this.fCount++;
        if (3 === this.fCount) {
          this.bodySpr.getComponent(cc.Sprite).spriteFrame = this.bodySFS[2];
        } else {
          6 === this.fCount && this.remove(0);
        }
      } else {
        this.node.y += this.v * e;
        this.node.y >= 799 && this.remove(0);
      }
    }
  };
  _ctor.collTimes = 0;
  __decorate([ccp_property(cc.Label)], _ctor.prototype, "label", undefined);
  __decorate([ccp_property(cc.Node)], _ctor.prototype, "bodySpr", undefined);
  __decorate([ccp_property(cc.SpriteFrame)], _ctor.prototype, "bodySFS", undefined);
  __decorate([ccp_property(cc.BoxCollider)], _ctor.prototype, "collBody", undefined);
  return o = __decorate([ccp_ccclass], _ctor);
}(cc.Component);
exports.default = def_Bullet2;